﻿using System;
using DAL.POCO;
using DAL.Repositories;
using System.Web.UI.WebControls;

namespace GameAdmin.Pages
{
    public partial class score : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            gw.RowDeleting += new GridViewDeleteEventHandler(gw_RowDeleting);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty((string)RouteData.Values["loginName"])) return;

            GetUserScores();
        }

        void gw_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int idToDelete = Int32.Parse(gw.Rows[e.RowIndex].Cells[0].Text);
            ScoreRepository.Delete(idToDelete);

            GetUserScores();
        }

        private void GetUserScores()
        {
            string loginName = (string)RouteData.Values["loginName"];
            literalLoginName.Text = loginName;

            gw.DataSource = ScoreRepository.GetScores(loginName);
            gw.DataBind();
        }
    }
}